const nodemailer = require("nodemailer");

/***
 * @class 邮件发送
 */
class MailUtil {
    constructor() {
        this.transport = nodemailer.createTransport({
            host: "smtp.163.com",
            port: 465,
            secure: true, //是否启用信息加密
            auth: {
                user: "mh475201314@163.com",
                pass: "11langxiaoshi" //这个地方填授权码
            }
        })
    }
    /**
     * 
     * @param {string} to 邮件的接收者 
     * @param {string}} 邮件标题 
     * @param {string} 邮件内容  可以是html字符串
     */
    sendMail(to, subject,text) {
        return new Promise((resolve,reject)=>{
            this.transport.sendMail({
                from:"mh475201314@163.com",
                to:to,
                subject:subject,
                html:text
            },(err,info)=>{
                if(err){
                    reject(err);
                }
                else{
                    resolve(info);
                }
            })
        });
    }
}

module.exports = MailUtil;